package module.main.view
{
	
	import com.darwin.darwinMVC.mvc.Command;
	import com.darwin.darwinUI.containers.Box;
	import com.darwin.darwinUI.controls.LabelButton;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.manager.PopUpManager;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	import main.AppConfig;
	import main.AppControllerList;
	
	import module.main.cmds.MainCmdConst;
	import module.main.event.MainEvent;
	
	public class LoginBox extends UIComponent
	{
		private var _loginTxt:TextField;
		private var _determineBtn:LabelButton;
		private var _loginContainer:UIComponent;
		public function LoginBox()
		{
			super();
			width = 500;
			height = 500;
			background = getBoxSkin();
			init();
		}
		private function getBoxSkin():Sprite
		{
			var boxSkin:Sprite = new Sprite;
			boxSkin.graphics.beginFill(0x333333);
			boxSkin.graphics.drawRoundRect(0,0,width,height,20);
			boxSkin.graphics.endFill();
			return boxSkin;
		}
		private function init():void
		{
			_loginTxt = new TextField();
			_loginTxt.height = 20;
			_loginTxt.width = 100;
			_loginTxt.type = TextFieldType.INPUT;
			_loginTxt.background = true;
			_loginTxt.x = (this.width - _loginTxt.width) / 2;
			_loginTxt.y = 100;
			_loginTxt.restrict = "0-9";
			_loginTxt.text = "";
			_loginContainer = new UIComponent;
			_loginContainer.addChild(_loginTxt);
			addChild(_loginContainer);
			
			_determineBtn = getLabBtn("确定");
			_determineBtn.x = (this.width - _determineBtn.width) / 2;
			_determineBtn.y = 300;
			_loginContainer.addChild(_determineBtn);
			
			_determineBtn.addEventListener(MouseEvent.CLICK,clickHandle);
			
		}
		private function clickHandle(e:MouseEvent):void
		{
			if(_loginTxt.text == "")
			{
				return;
			}
			this.parent.removeChild(this);
			AppConfig.getInstance().userId = _loginTxt.text;
			var loginEvt:MainEvent = new MainEvent(MainEvent.CLICK_LOGIN_EVENT,true,false);
			dispatchEvent(loginEvt);
		}
		
		private function getLabBtn(str:String):LabelButton
		{
			var sprit:Sprite = new Sprite();
			sprit.graphics.beginFill(0x6666660);
			sprit.graphics.drawRoundRect(0,0,20,20,5);
			sprit.graphics.endFill();
			var ptn:LabelButton = new LabelButton(str,sprit);
			return ptn;
		}
	}
}